﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QD.Data.Page
{
    public class PagerInfo
    {
        public int Begin { get; private set; }
        public int End { get; private set; }
        public int Current { get; private set; }
        public int Padding { get; private set; }
        public int PageCount { get; private set; }
        public int Records { get; private set; }
        public int PageSize { get; private set; }

        public PagerInfo(int page, int total, int pagesize, int padding)
        {
            this.Current = page <= 0 ? 1 : page;
            this.Records = total;
            this.PageSize = pagesize;
            this.Padding = padding;
            this.PageCount = this.Records / this.PageSize + 1;
            if (this.PageCount <= padding)
            {
                this.Begin = 1; this.End = this.PageCount;
            }
            else if (page == 1)
            {
                this.Begin = 1; this.End = padding;
            }
            else
            {
                this.Begin = page - padding / 2;
                if (this.Begin <= 0) this.Begin = 1;
                this.End = this.Begin + padding - 1;
                if (this.Begin > this.PageCount - padding + 1)
                    this.Begin = this.PageCount - padding + 1;
            }
            if (this.End > this.PageCount) this.End = this.PageCount;
        }
    }

}

